import 'package:flutter/material.dart';

void main() => runApp(RouteCalculate());

class RouteCalculate extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'RouteCalculate',
      routes: {
        "secondPage": (context) => SecondPage(),
      },
      home: FirstPage(),
    );
  }
}

class FirstPage extends StatefulWidget {
  @override
  _FirstPageState createState() => _FirstPageState();
}

class _FirstPageState extends State<FirstPage> {
  int _total = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('first page'),
      ),
        body: Column(
          children: <Widget>[
            Text('total: $_total'),
            RaisedButton(
              onPressed: () => Navigator.pushNamed(context, 'secondPage', arguments: { "a": 12, "b": 3}).then((msg) {
                setState(() {

                  _total = msg;
                });
              }),
              child: Text("去第二页"),
            )
          ],
        )

    );
  }
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var msg = ModalRoute.of(context).settings.arguments as Map<String, int>;
    int sum = msg['a'] + msg['b'];
    return Scaffold(
      appBar: AppBar(
        title: Text('second page'),
      ),
      body: Column(
        children: <Widget>[
          Text('收到了两个参数的和 $sum'),
          RaisedButton(
            onPressed: () => Navigator.pop(context, sum),
            child: Text("回去"),
          )
        ],
      ),
    );
  }
}